<?php
/**
 * Provides profile editing interface
 */
?>
<html>
<head>
<?php
require_once '../dbms_university_courses_mvc/Model/model_require_once.php';
?>
</head>
<body>
<h1>Edit Profile</h1>
<?php
/* @var $profile Profile */
$profile = Profile::constructFrom_profile_id ( $_SESSION ['profile_id'] );

$profile->instantiate_javascript_object();
?>

<script type="text/javascript">
	function refreshImage(){
		document.images["profile_image"].src = "profile_images/<?php
		echo $profile->get_profile_id ();
		?>.jpg?" + Math.random();
	}
</script>
<table>
	<?php
	//student
	if ($profile->get_user_type_id () == 3) {
		?>
		<tr>
		<th>Department:</th>
		<td><?php
		/* @var $student Student */
		$students = $profile->getStudents ();
		$student = $students [0];
		/* @var $department Department */
		$department = Department::constructFrom_department_id ( $student->get_department_id () );
		echo $department->get_department_name ();
		?></td>
	</tr>
	<tr>
		<th>Enrolled:</th>
		<td><?php
		echo $student->get_year_enrolled ();
		?></td>
	</tr>
	<?php
	}
	?>
	<?php
	//instructor
	if ($profile->get_user_type_id () == 2) {
		?>
		<tr>
		<th>Department(s):</th>
		<td><?php
		/* @var $instructor Instructor */
		$instructors = $profile->getInstructors ();
		$instructor = $instructors [0];
		$instructorDepartments = InstructorDepartment::getInstructorDepartments_by_instructor_id ( $instructor->get_instructor_id () );
		
		/* @var $department Department */
		/* @var $instructorDepartment InstructorDepartment */
		$departmentList = "";
		foreach ( $instructorDepartments as $instructorDepartment ) {
			$department = Department::constructFrom_department_id ( $instructorDepartment->get_department_id () );
			$departmentList .= $department->get_department_name () . ", ";
		}
		if (strlen ( $departmentList ) > 2) {
			$departmentList = substr ( $departmentList, 0, strlen ( $departmentList ) - 2 );
		} 
		echo $departmentList;
		?></td>
	</tr>
	<?php
	}
	?>
	<tr>
		<th>First Name:</th>
		<td><?php
		$profile->print_first_name_input_setter ();
		?></td>
	</tr>
	<tr>
		<th>Last Name:</th>
		<td><?php
		$profile->print_last_name_input_setter ();
		?></td>
	</tr>
	<tr>
		<th>Gender:</th>
		<td><?php
		Gender::print_Gender_dropdown ( Gender::getGenders (), "gender", $profile->get_gender (), "Profile".$profile->get_profile_id().".set_gender" );
		?></td>
	</tr>
	<tr>
		<th>Date of Birth:</th>
		<td><?php
		$profile->print_date_of_birth_input_setter ();
		?></td>
	</tr>
	<tr>
		<th>Local Address:</th>
		<td><?php
		$profile->get_local_address();
		?></td>
	</tr>
	<tr>
		<th>Username:</th>
		<td><?php
		echo $profile->get_username ();
		?></td>
	</tr>
	<tr>
		<th>Password:</th>
		<td><?php
		$profile->print_password_input_setter ();
		?></td>
	</tr>
	<tr>
		<th>Picture:</th>
		<td><img id="profile_image"
			src="profile_images/<?php
			echo $profile->get_profile_id ();
			?>.jpg"
			width="200px"
		/> <br>
		<iframe src="controllers/image_uploader.php" width="375" height="120"
			style="border: 0px;"
		>Blah</iframe></td>
	</tr>
</table>
</body>
</html>